<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="查看流程业务信息" okText="通过" cancelText="取消" @cancel="cancelButton"  @ok="handleSubmit" width="60%">
    <BasicForm @register="registerForm" />
  </BasicModal>
  <itemCheckModal  @register="chenckModal"></itemCheckModal>
</template>
<script lang="ts" setup>
  import { defineProps, ref, computed, unref, reactive } from 'vue';
  import { BasicModal, useModalInner,useModal } from '/src/components/Modal';
  import { BasicForm, useForm } from '/src/components/Form';
  import { formSchemaQJ } from '../dsApply.data';
  import { getForm } from '../dsApply.api';
  import itemCheckModal from './itemCheckModal.vue';

  const [chenckModal, {openModal:addOpenModal}] = useModal();
  // 声明Emits
  const emit = defineEmits(['success', 'register']);
  const props = defineProps({ dictId: String });
  const isUpdate = ref(true);
  const tempObj=ref();
  //表单配置
  const [registerForm, { setProps,resetFields, setFieldsValue, validate }] = useForm({
    schemas: formSchemaQJ,
    showActionButtonGroup: false,
    mergeDynamicData: props,
    labelCol: {
      xs: { span: 24 },
      sm: { span: 4 },
    },
    wrapperCol: {
      xs: { span: 24 },
      sm: { span: 18 },
    },
  });
  //表单赋值
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    // lcId.value=data.record.id;
    tempObj.value=data.record;
    console.log("data.record",data.record);
    await getForm({tableId:data.record.tableId,tableName:data.record.tableName})
                  .then((res)=>{
             // //重置表单
             resetFields();
             setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter});
            isUpdate.value = !!data?.isUpdate;
            if (unref(isUpdate)) {
              //表单赋值
               setFieldsValue({
                ...res,
              });
            }
          })
           // 隐藏底部时禁用整个表单
       setProps({ disabled: data?.showFooter })
  });

  //设置标题
  const getTitle = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));

  //表单驳回事件
  async function cancelButton(v){
    // let recold=tempObj.value;
    // addOpenModal(true, {
    //      recold,
    //      isUpdate: 2,
    //      showFooter: true,
    //    });
  }
  //表单提交事件
  async function handleSubmit(v) {
    let recold=tempObj.value;
    closeModal();
    addOpenModal(true, {
         recold,
         isUpdate: 1,
         showFooter: true,
       });
  }
</script>
